This package implements various tests, visualizations, and metrics for use with environmental niche models (ENMs) and species distribution models (SDMs).
At present, ENMTools is downloadable from https://github.com/danlwarren/ENMTools. There are multiple ways to download it. The easiest is to use devtools and install from GitHub.
Run the following code from your R console:
install.packages("devtools")
library(devtools)
install_github("danlwarren/ENMTools")
library(ENMTools)
A zipped version of the package is available at https://github.com/danlwarren/ENMTools/archive/master.zip. To install from the zip file, download a copy of it to your system. Once it’s finished downloading, type the following (where PATH is the path to the zip file):
install.packages("devtools")
library(devtools)
install_local("PATH")
library(ENMTools)
First we’re going to load in some environmental data.
env.files <- list.files(path = "test/testdata/", pattern = "pc", full.names = TRUE)
env <- stack(env.files)
names(env) <- c("layer.1", "layer.2", "layer.3", "layer.4")
env <- setMinMax(env)
ENMTools is primarily designed to examine patterns of similarity and difference between ENMs for different species. In order to simplify interactions with the functions in ENMTools, you need to put your data for each of your species into an enmtools.species object. You can create and view an empty enmtools.species object just by typing:
ahli <- enmtools.species()
ahli
##
##
## Range raster not defined.
##
## Presence points not defined.
##
## Background points not defined.
##
## Species name not defined.
You can add data to this object manually:
names(ahli)
## [1] "range" "presence.points" "background.points"
## [4] "models" "species.name"
ahli$species.name <- "ahli"
ahli$presence.points <- read.csv("test/testdata/ahli.csv")[,3:4]
ahli$range <- background.raster.buffer(ahli$presence.points, 50000, mask = env)
ahli$background.points <- background.points.buffer(points = ahli$presence.points,
radius = 20000, n = 1000, mask = env[[1]])
ahli
##
##
## Range raster:
## class : RasterLayer
## dimensions : 418, 1535, 641630 (nrow, ncol, ncell)
## resolution : 0.008333333, 0.008333333 (x, y)
## extent : -86.90809, -74.11642, 19.80837, 23.2917 (xmin, xmax, ymin, ymax)
## coord. ref. : NA
## data source : in memory
## names : layer.1
## values : 1, 1 (min, max)
##
##
##
## Presence points (first ten only):
##
## Longitude Latitude
## ---------- ---------
## -80.0106 21.8744
## -79.9086 21.8095
## -79.8065 21.7631
## -79.8251 21.8095
## -79.8807 21.8374
## -79.9550 21.8374
## -80.3446 22.0136
## -80.2983 21.9951
## -80.1776 21.9023
## -80.1591 21.9673
##
##
## Background points (first ten only):
##
## Longitude Latitude
## ---------- ---------
## -79.62892 21.69587
## -79.97059 21.97920
## -79.90392 21.80420
## -80.15392 21.97920
## -80.05392 21.93754
## -80.17059 21.87087
## -80.42059 22.13754
## -79.76226 21.80420
## -80.16226 22.14587
## -80.23726 22.07920
##
##
## Species name: ahli
Or you can add bits of it when the object is created:
allogus <- enmtools.species(species.name = "allogus",
presence.points = read.csv("test/testdata/allogus.csv")[,3:4])
allogus$range <- background.raster.buffer(allogus$presence.points, 50000, mask = env)
allogus$background.points <- background.points.buffer(points = allogus$presence.points,
radius = 20000, n = 1000, mask = env[[1]])
allogus
##
##
## Range raster:
## class : RasterLayer
## dimensions : 418, 1535, 641630 (nrow, ncol, ncell)
## resolution : 0.008333333, 0.008333333 (x, y)
## extent : -86.90809, -74.11642, 19.80837, 23.2917 (xmin, xmax, ymin, ymax)
## coord. ref. : NA
## data source : in memory
## names : layer.1
## values : 1, 1 (min, max)
##
##
##
## Presence points (first ten only):
##
## Longitude Latitude
## ---------- ---------
## -79.2527 22.2109
## -78.7774 22.2241
## -78.6189 22.2373
## -78.1039 21.1809
## -78.0247 21.1809
## -77.9983 20.9301
## -77.9719 21.7091
## -77.9719 21.5507
## -77.9323 21.6167
## -77.9323 20.7320
##
##
## Background points (first ten only):
##
## Longitude Latitude
## ---------- ---------
## -77.07059 20.71254
## -75.85392 20.45420
## -75.97059 20.27920
## -77.42059 20.99587
## -75.64559 20.11254
## -74.73726 20.27087
## -75.28726 20.51254
## -75.76226 21.03754
## -76.29559 20.16254
## -77.07892 20.76254
##
##
## Species name: allogus
ENMTools contains functions to simplify the ENM construction process. Using enmtools.species objects and the correct modeling commands, we can build models very quickly. These commands are primarily wrappers to dismo model construction and projection functions, and at present are only available for GLM, Maxent, Domain, and Bioclim models. One of the nice bits about this setup is that it allows enmtools to automatically generate suitability maps, do model evaluation, and plot the marginal suitability of habitat for each variable separately.
GLMs usually require the user to supply a formula, an enmtools.species object, and some environmental data. If your formula is a strictly additive function of all of the environmental layers in env, though, enmtools.glm will build a formula automatically.
ahli.glm <- enmtools.glm(species = ahli, env = env, f = pres ~ layer.1 + layer.2 + layer.3 + layer.4, test.prop = 0.2)
## Adding environmental data to species ahli
## Processing presence points...
## Processing background points...
allogus.glm <- enmtools.glm(species = allogus, env = env, f = pres ~ layer.1 + layer.2 + layer.3 + layer.4, test.prop = 0.2)
## Adding environmental data to species allogus
## Processing presence points...
## Processing background points...
ahli.glm
##
##
## Formula: presence ~ layer.1 + layer.2 + layer.3 + layer.4
## <environment: 0x7fbaefdcbd58>
##
##
## Data table (top ten lines):
##
## Longitude Latitude layer.1 layer.2 layer.3 layer.4 presence
## --- ---------- --------- -------- -------- -------- -------- ---------
## 2 -79.9086 21.8095 2289 1732 957 231 1
## 3 -79.8065 21.7631 2158 1870 983 253 1
## 4 -79.8251 21.8095 2207 1877 967 259 1
## 5 -79.8807 21.8374 2244 1828 945 249 1
## 6 -79.9550 21.8374 2250 1766 919 235 1
## 7 -80.3446 22.0136 2201 1822 978 277 1
## 8 -80.2983 21.9951 2214 1786 986 284 1
## 9 -80.1776 21.9023 2287 1722 992 266 1
## 11 -80.1498 21.9858 3042 841 1371 221 1
## 14 -80.2148 21.9394 2329 1692 1018 269 1
##
##
## Model:
## Call:
## glm(formula = f, family = "binomial", data = analysis.df[, -c(1,
## 2)])
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -0.36129 -0.18219 -0.12629 -0.08288 3.09008
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 58.6901863 26.6660751 2.201 0.0277 *
## layer.1 -0.0158121 0.0068223 -2.318 0.0205 *
## layer.2 -0.0145770 0.0071189 -2.048 0.0406 *
## layer.3 -0.0014132 0.0076543 -0.185 0.8535
## layer.4 0.0009006 0.0231168 0.039 0.9689
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 130.29 on 1011 degrees of freedom
## Residual deviance: 120.69 on 1007 degrees of freedom
## AIC: 130.69
##
## Number of Fisher Scoring iterations: 8
##
##
##
## Model fit (training data): class : ModelEvaluation
## n presences : 12
## n absences : 1000
## AUC : 0.763625
## cor : 0.08825875
## max TPR+TNR at : -4.765926
##
##
## Environment space model fit (training data): class : ModelEvaluation
## n presences : 12
## n absences : 10000
## AUC : 0.4591583
## cor : -0.02573706
## max TPR+TNR at : 0.00840667
##
##
## Proportion of data wittheld for model fitting: 0.2
##
## Model fit (test data): class : ModelEvaluation
## n presences : 4
## n absences : 1000
## AUC : 0.762
## cor : 0.04960023
## max TPR+TNR at : -4.465056
##
##
## Environment space model fit (test data): class : ModelEvaluation
## n presences : 4
## n absences : 10000
## AUC : 0.455325
## cor : -0.01502727
## max TPR+TNR at : 0.01132325
##
##
## Suitability:
## class : RasterLayer
## dimensions : 418, 1535, 641630 (nrow, ncol, ncell)
## resolution : 0.008333333, 0.008333333 (x, y)
## extent : -86.90809, -74.11642, 19.80837, 23.2917 (xmin, xmax, ymin, ymax)
## coord. ref. : NA
## data source : in memory
## names : layer
## values : 1.194651e-06, 0.9999423 (min, max)
##
##
##
## Notes:
Notice this produces the same formula as:
ahli.glm <- enmtools.glm(species = ahli, env = env, test.prop = 0.2)
## Adding environmental data to species ahli
## Processing presence points...
## Processing background points...
ahli.glm
##
##
## Formula: presence ~ layer.1 + layer.2 + layer.3 + layer.4
## <environment: 0x7fbaefe52ee8>
##
##
## Data table (top ten lines):
##
## Longitude Latitude layer.1 layer.2 layer.3 layer.4 presence
## --- ---------- --------- -------- -------- -------- -------- ---------
## 1 -80.0106 21.8744 2765 1235 1174 252 1
## 2 -79.9086 21.8095 2289 1732 957 231 1
## 3 -79.8065 21.7631 2158 1870 983 253 1
## 4 -79.8251 21.8095 2207 1877 967 259 1
## 5 -79.8807 21.8374 2244 1828 945 249 1
## 6 -79.9550 21.8374 2250 1766 919 235 1
## 7 -80.3446 22.0136 2201 1822 978 277 1
## 9 -80.1776 21.9023 2287 1722 992 266 1
## 10 -80.1591 21.9673 2984 965 1311 237 1
## 13 -80.1776 21.9673 2914 1020 1256 237 1
##
##
## Model:
## Call:
## glm(formula = f, family = "binomial", data = analysis.df[, -c(1,
## 2)])
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -0.49704 -0.17927 -0.12401 -0.09186 3.06707
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 34.766487 26.834419 1.296 0.195
## layer.1 -0.008971 0.006683 -1.342 0.179
## layer.2 -0.007980 0.007371 -1.083 0.279
## layer.3 0.001452 0.008142 0.178 0.858
## layer.4 -0.023509 0.027523 -0.854 0.393
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 130.29 on 1011 degrees of freedom
## Residual deviance: 121.55 on 1007 degrees of freedom
## AIC: 131.55
##
## Number of Fisher Scoring iterations: 8
##
##
##
## Model fit (training data): class : ModelEvaluation
## n presences : 12
## n absences : 1000
## AUC : 0.7583333
## cor : 0.09019855
## max TPR+TNR at : -4.694466
##
##
## Environment space model fit (training data): class : ModelEvaluation
## n presences : 12
## n absences : 10000
## AUC : 0.4745917
## cor : -0.02036191
## max TPR+TNR at : 0.00899583
##
##
## Proportion of data wittheld for model fitting: 0.2
##
## Model fit (test data): class : ModelEvaluation
## n presences : 4
## n absences : 1000
## AUC : 0.793875
## cor : 0.07488414
## max TPR+TNR at : -4.591244
##
##
## Environment space model fit (test data): class : ModelEvaluation
## n presences : 4
## n absences : 10000
## AUC : 0.498425
## cor : -0.01075775
## max TPR+TNR at : 0.01000016
##
##
## Suitability:
## class : RasterLayer
## dimensions : 418, 1535, 641630 (nrow, ncol, ncell)
## resolution : 0.008333333, 0.008333333 (x, y)
## extent : -86.90809, -74.11642, 19.80837, 23.2917 (xmin, xmax, ymin, ymax)
## coord. ref. : NA
## data source : in memory
## names : layer
## values : 2.859528e-11, 0.9989764 (min, max)
##
##
##
## Notes:
If you want a more complicated formula, though (e.g., with interactions or polynomial effects), you’ll need to supply that manually.
ahli.glm <- enmtools.glm(species = ahli, env = env, f = pres ~ poly(layer.1, 2) + poly(layer.2, 2) + poly(layer.3, 2) + poly(layer.4, 2), test.prop = 0.2)
## Adding environmental data to species ahli
## Processing presence points...
## Processing background points...
ahli.glm
##
##
## Formula: presence ~ poly(layer.1, 2) + poly(layer.2, 2) + poly(layer.3,
## 2) + poly(layer.4, 2)
## <environment: 0x7fbaed83d2a8>
##
##
## Data table (top ten lines):
##
## Longitude Latitude layer.1 layer.2 layer.3 layer.4 presence
## --- ---------- --------- -------- -------- -------- -------- ---------
## 2 -79.9086 21.8095 2289 1732 957 231 1
## 4 -79.8251 21.8095 2207 1877 967 259 1
## 5 -79.8807 21.8374 2244 1828 945 249 1
## 6 -79.9550 21.8374 2250 1766 919 235 1
## 8 -80.2983 21.9951 2214 1786 986 284 1
## 10 -80.1591 21.9673 2984 965 1311 237 1
## 11 -80.1498 21.9858 3042 841 1371 221 1
## 12 -80.1220 21.9301 2898 1033 1231 242 1
## 13 -80.1776 21.9673 2914 1020 1256 237 1
## 14 -80.2148 21.9394 2329 1692 1018 269 1
##
##
## Model:
## Call:
## glm(formula = f, family = "binomial", data = analysis.df[, -c(1,
## 2)])
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -0.81494 -0.16363 -0.11137 -0.07411 3.13133
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -5.0501 0.4749 -10.634 <2e-16 ***
## poly(layer.1, 2)1 -91.0858 66.0532 -1.379 0.168
## poly(layer.1, 2)2 -5.2969 28.4398 -0.186 0.852
## poly(layer.2, 2)1 -108.0728 78.0560 -1.385 0.166
## poly(layer.2, 2)2 -1.2897 30.4583 -0.042 0.966
## poly(layer.3, 2)1 -6.5647 43.7339 -0.150 0.881
## poly(layer.3, 2)2 17.2902 16.7761 1.031 0.303
## poly(layer.4, 2)1 -1.1952 18.4234 -0.065 0.948
## poly(layer.4, 2)2 -8.8614 14.2461 -0.622 0.534
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 130.29 on 1011 degrees of freedom
## Residual deviance: 113.71 on 1003 degrees of freedom
## AIC: 131.71
##
## Number of Fisher Scoring iterations: 8
##
##
##
## Model fit (training data): class : ModelEvaluation
## n presences : 12
## n absences : 1000
## AUC : 0.8111667
## cor : 0.1328929
## max TPR+TNR at : -4.468052
##
##
## Environment space model fit (training data): class : ModelEvaluation
## n presences : 12
## n absences : 10000
## AUC : 0.48545
## cor : -0.02227972
## max TPR+TNR at : 0.00732717
##
##
## Proportion of data wittheld for model fitting: 0.2
##
## Model fit (test data): class : ModelEvaluation
## n presences : 4
## n absences : 1000
## AUC : 0.736625
## cor : 0.04162921
## max TPR+TNR at : -4.596607
##
##
## Environment space model fit (test data): class : ModelEvaluation
## n presences : 4
## n absences : 10000
## AUC : 0.439975
## cor : -0.01449601
## max TPR+TNR at : 0.00988628
##
##
## Suitability:
## class : RasterLayer
## dimensions : 418, 1535, 641630 (nrow, ncol, ncell)
## resolution : 0.008333333, 0.008333333 (x, y)
## extent : -86.90809, -74.11642, 19.80837, 23.2917 (xmin, xmax, ymin, ymax)
## coord. ref. : NA
## data source : in memory
## names : layer
## values : 2.220446e-16, 0.9999997 (min, max)
##
##
##
## Notes:
To check out the marginal response functions, you only need to type
ahli.glm$response.plots
## $layer.1
##
## $layer.2
##
## $layer.3
##
## $layer.4
You can also visualize your models and data in a 2D environment space using any pair of layers from your environment stack. These plots hold all non-plotted variables (layer.1 and layer.3 in this case) constant at their mean value across all presence points, then vary the plotted variables between the minimum and maximum values in env.
The suit.plot shows you suitability in environment space as a function of your two variables, with brighter colors representing variable combinations predicted to be more suitable. The points represent the occurrence points for your species in that environment space.
The colored raster of the background.plot shows you the density of background points in environment space, while the white points again represent your occurrence points in environment space.
visualize.enm(ahli.glm, env, layers = c("layer.2", "layer.4"))
## $background.plot
##
## $suit.plot
The procedure for building Bioclim, Domain, and Maxent models is similar to the procedure for GLMs, with the exception that you do not need to pass a formula to the model function. Note that running Maxent models requires a bit of extra setup; see dismo documentation for details.
ahli.gam <- enmtools.gam(ahli, env, test.prop = 0.2)
ahli.dm <- enmtools.dm(ahli, env, test.prop = 0.2)
ahli.bc <- enmtools.bc(ahli, env, test.prop = 0.2)
ahli.mx <- enmtools.maxent(ahli, env, test.prop = 0.2)
ENMTools provides a number of metrics for ENMs and for similarities between ENMs. These include measures of niche breadth, based on Levins(1968). An important caveat when interpreting these metrics is that they are driven to some (variable) extent by the availability of different combinations of environmental variables. As such they are more accurately interpreted as a measurment of the smoothness of the geographic distribution of suitability scores than as an estimate of the breadth of the fundamental niche; an organism with narrow fundamental niche breadth that nonetheless encompasses a set of environmental conditions that is quite common will have a high breadth when measured using ENMs, while having a low breadth in environment space.
raster.breadth(ahli.glm)
## $B1
## [1] 0.8497318
##
## $B2
## [1] 0.1368177
ENMTools also provides metrics for measuring similarity between ENMs. These include Schoener’s D (Schoener 1968), I (Warren et al. 2008), and the Spearman rank correlation coefficient between two rasters. While D and I are commonly used in the ENM literature, they may tend to overestimate similarity between ENMs when many grid cells are of similar values (e.g., when two species prefer different habitat but the region contains a great deal of habitat that is unsuitable for both).
raster.overlap(ahli.glm, allogus.glm)
## $D
## [1] 0.2688075
##
## $I
## [1] 0.5305886
##
## $rank.cor
## [1] 0.148414
A new feature of the R version of ENMTools is that you can now use these same metrics in the n-dimensional space of all combinations of environmental variables, instead of restricting your measures of model similarity to those sets of conditions that appear in the training region. This is done by repeatedly drawing Latin hypercube samples from the space of all possible combinations of environmental variables given the min and max of each variable within the training region. ENMTools continues to draw samples until subsequent iterations differ by less than a specified tolerance value. Lower tolerance values result in more precise estimates of overlap, but can take much longer to calculate.
env.overlap(ahli.glm, allogus.glm, env, tolerance = .001)
## $env.D
## [1] 0.1858338
##
## $env.I
## [1] 0.3816579
##
## $env.cor
## [1] -0.2860167
In this example, we will run a niche identity (also called equivalency) test, as in Warren et al. 2008. This test takes the presence points for a pair of species and randomly reassigns them to each species, then builds ENMs for these randomized occurrences. By doing this many times, we can estimate the probability distribution for ENM overlap between species under the null hypothesis that the two species’ occurrences in the environment are effectively a random draw from the same underlying distribution. Note that niche evolution is only one of many reasons why two species’ realized environmental distributions might cause departures from this null hypothesis. See Warren et al. 2014 for details.
To run an identity test, we need to decide what type of models we will build, how many replicates we will run, and (in the case of GLM) a model formula to use for empirical models and the Monte Carlo replicates. The resulting object contains the replicate models, p values, and plots of the results. Typically idenity tests are run with at least 99 replicates, but we are using a smaller number here for the sake of execution time.
NOTE: In order for models to be comparable, both empirical and pseudoreplicate models for the identity test are conducted with pseudoabsence points pooled for the two species being compared.
id.glm <- identity.test(species.1 = ahli, species.2 = allogus, env = env, type = "glm", nreps = 4)
id.glm
##
##
##
##
## Identity test ahli vs. allogus
##
## Identity test p-values:
## D I rank.cor env.D env.I env.cor
## 0.2 0.2 0.2 0.2 0.2 0.2
##
##
## Replicates:
##
##
## D I rank.cor env.D env.I env.cor
## ---------- ---------- ---------- ----------- ---------- ---------- -----------
## empirical 0.2227886 0.4647195 -0.5744911 0.0043662 0.0301523 -0.6911973
## rep 1 0.8882180 0.9897955 0.9375940 0.8384662 0.9774142 0.9543931
## rep 2 0.7691570 0.9637369 0.9537696 0.8043391 0.9625830 0.9555306
## rep 3 0.6229698 0.8946725 0.8022920 0.6675531 0.8880251 0.7667348
## rep 4 0.8016827 0.9708477 0.5145647 0.7100077 0.9273393 0.7416384
The background or similarity test compares the overlap seen between two species’ ENMs to the overlap expected by chance if one or both species was effectively choosing habitat at random from within their broad geographic range. The purpose of this test is to correct for the availability of habitat and ask whether the observed similarity between species or populations is significantly more (or less) than expected given the available set of environments in the regions in which they occur.
NOTE: In order for models to be comparable, both empirical and pseudoreplicate models for the background test are conducted with pseudoabsence points pooled for the two species being compared.
In Warren et al. 2008, we developed this test in the context of comparing one species’ actual occurrence to the random background occurrences of the other species. This is what we call an “asymmetric” test, and in our case we did the test in both directions with the idea that we might compare the results of A vs. B background to the results of B vs. A background. This may be informative in some cases, but many people have also found this asymmetry confusing (and indeed it is often difficult to interpret). For that reason, the background test here can be conducted against a null hypothesis that is generated from “asymmetric” (species.1 vs species.2 background) or “symmetric” (species.1 background vs. species.2 background) comparisons.
Here, for instance, is a Bioclim background test using the classical asymmetric approach:
bg.bc.asym <- background.test(species.1 = ahli, species.2 = allogus, env = env, type = "bc", nreps = 4, test.type = "asymmetric" )
bg.bc.asym
##
##
##
##
## Asymmetric background test ahli vs. allogus background
##
## background test p-values:
## D I rank.cor env.D env.I env.cor
## 0.2 0.2 0.2 0.2 0.2 0.2
##
##
## Replicates:
##
##
## D I rank.cor env.D env.I env.cor
## ---------- ---------- ---------- ---------- ---------- ---------- ----------
## empirical 0.1328502 0.3177390 0.0706201 0.0219928 0.1143735 0.0874469
## rep 1 0.1563548 0.3547921 0.1977984 0.0469009 0.1706080 0.1044339
## rep 2 0.1661097 0.3538175 0.1977206 0.0864565 0.1842156 0.1153959
## rep 3 0.1758236 0.3813949 0.2191566 0.0403831 0.1807830 0.1208625
## rep 4 0.1424299 0.3303174 0.1106967 0.0747233 0.2254529 0.1901440
And here is a Domain background test using the symmetric approach:
bg.dm.sym <- background.test(species.1 = ahli, species.2 = allogus, env = env, type = "dm", nreps = 4, test.type = "symmetric" )
bg.dm.sym
##
##
##
##
## Symmetric background test ahli background vs. allogus background
##
## background test p-values:
## D I rank.cor env.D env.I env.cor
## 0.2 0.2 0.2 0.2 0.2 0.2
##
##
## Replicates:
##
##
## D I rank.cor env.D env.I env.cor
## ---------- ---------- ---------- ---------- ---------- ---------- ----------
## empirical 0.4929334 0.7052122 0.2916150 0.1031175 0.3043173 0.2195090
## rep 1 0.9530369 0.9964033 0.7243118 0.6988416 0.8438498 0.7276648
## rep 2 0.9592626 0.9966281 0.6396891 0.7249677 0.8687656 0.7464145
## rep 3 0.9255741 0.9902051 0.5227462 0.3031685 0.5320062 0.4283415
## rep 4 0.9510701 0.9962552 0.7300755 0.7300094 0.8818461 0.8230906
Using enmtools.species objects also provides a simplified interface to the niche equivalency and similarity tests (or identity and background tests, respectively) that were developed by Broennimann et al. (2012). These tests do not rely on ENMs, instead using kernel density smoothing to estimate density of the species in environment space. Ecospat also uses the density of the available environment to correct for availability when measuring overlaps, so that overlaps are not strictly driven by availability of combinations of environmental variables.
These tests only work with two environmental axes, so they are often done with the top two PC axes of a set of environments. In our case we’ll just pick a couple of environmental layers, though (layer.1 and layer.2). Here’s an equivalency/identity test:
esp.id <- enmtools.ecospat.id(ahli, allogus, env[[c("layer.1", "layer.2")]])
## ===========================================================================
esp.id
##
##
##
##
## Ecospat identity test ahli vs. allogus
##
## Species Longitude Latitude layer.1 layer.2
## -------- ---------- --------- -------- --------
## ahli -80.0106 21.8744 2765 1235
## ahli -79.9086 21.8095 2289 1732
## ahli -79.8065 21.7631 2158 1870
## ahli -79.8251 21.8095 2207 1877
## ahli -79.8807 21.8374 2244 1828
## ahli -79.9550 21.8374 2250 1766
##
##
## Species Longitude Latitude layer.1 layer.2
## -------- ---------- --------- -------- --------
## ahli.bg -79.62892 21.69587 2018 2002
## ahli.bg -79.97059 21.97920 2770 1270
## ahli.bg -79.90392 21.80420 2258 1815
## ahli.bg -80.15392 21.97920 3020 856
## ahli.bg -80.05392 21.93754 2874 1149
## ahli.bg -80.17059 21.87087 2449 1518
##
##
## Species Longitude Latitude layer.1 layer.2
## ----------- ---------- --------- -------- --------
## allogus.bg -79.2527 22.2109 2656 1683
## allogus.bg -78.7774 22.2241 2373 1967
## allogus.bg -78.6189 22.2373 2317 1980
## allogus.bg -78.1039 21.1809 2461 1669
## allogus.bg -78.0247 21.1809 2437 1684
## allogus.bg -77.9983 20.9301 2315 1746
##
##
## Species Longitude Latitude layer.1 layer.2
## -------- ---------- --------- -------- --------
## allogus -77.07059 20.71254 2076 1795
## allogus -75.85392 20.45420 2390 1217
## allogus -75.97059 20.27920 2158 1581
## allogus -77.42059 20.99587 2372 1679
## allogus -75.64559 20.11254 2163 1368
## allogus -74.73726 20.27087 2245 1105
##
##
## Species Longitude Latitude layer.1 layer.2
## ----------- ---------- --------- -------- --------
## background -80.91226 23.27087 2495 1993
## background -80.90392 23.27087 2504 2000
## background -80.93726 23.26254 2500 1993
## background -80.92892 23.26254 2500 1993
## background -80.92059 23.26254 2509 2002
## background -80.91226 23.26254 2504 2000
##
##
## ecospat.id test p-values:
## D I
## 0.02 0.02
## TableGrob (3 x 2) "arrange": 6 grobs
## z cells name grob
## 1 1 (1-1,1-1) arrange gtable[layout]
## 2 2 (1-1,2-2) arrange gtable[layout]
## 3 3 (2-2,1-1) arrange gtable[layout]
## 4 4 (2-2,2-2) arrange gtable[layout]
## 5 5 (3-3,1-1) arrange gtable[layout]
## 6 6 (3-3,2-2) arrange gtable[layout]
And here’s a symmetric background test. The difference between symmetric and asymmetric for these tests is the same as for the background tests presented above.
esp.bg.sym <- enmtools.ecospat.bg(ahli, allogus, env[[c("layer.1", "layer.3")]], test.type = "symmetric")
## ===========================================================================
esp.bg.sym
##
##
##
##
## Ecospat background test symmetric ahli vs. allogus
##
## Species Longitude Latitude layer.1 layer.3
## -------- ---------- --------- -------- --------
## ahli -80.0106 21.8744 2765 1174
## ahli -79.9086 21.8095 2289 957
## ahli -79.8065 21.7631 2158 983
## ahli -79.8251 21.8095 2207 967
## ahli -79.8807 21.8374 2244 945
## ahli -79.9550 21.8374 2250 919
##
##
## Species Longitude Latitude layer.1 layer.3
## -------- ---------- --------- -------- --------
## ahli.bg -79.62892 21.69587 2018 1094
## ahli.bg -79.97059 21.97920 2770 1152
## ahli.bg -79.90392 21.80420 2258 957
## ahli.bg -80.15392 21.97920 3020 1350
## ahli.bg -80.05392 21.93754 2874 1208
## ahli.bg -80.17059 21.87087 2449 1059
##
##
## Species Longitude Latitude layer.1 layer.3
## ----------- ---------- --------- -------- --------
## allogus.bg -79.2527 22.2109 2656 1097
## allogus.bg -78.7774 22.2241 2373 1067
## allogus.bg -78.6189 22.2373 2317 1065
## allogus.bg -78.1039 21.1809 2461 846
## allogus.bg -78.0247 21.1809 2437 877
## allogus.bg -77.9983 20.9301 2315 907
##
##
## Species Longitude Latitude layer.1 layer.3
## -------- ---------- --------- -------- --------
## allogus -77.07059 20.71254 2076 909
## allogus -75.85392 20.45420 2390 1116
## allogus -75.97059 20.27920 2158 899
## allogus -77.42059 20.99587 2372 871
## allogus -75.64559 20.11254 2163 1003
## allogus -74.73726 20.27087 2245 1189
##
##
## Species Longitude Latitude layer.1 layer.3
## ----------- ---------- --------- -------- --------
## background -80.91226 23.27087 2495 1075
## background -80.90392 23.27087 2504 1082
## background -80.93726 23.26254 2500 1077
## background -80.92892 23.26254 2500 1077
## background -80.92059 23.26254 2509 1082
## background -80.91226 23.26254 2504 1080
##
##
## ecospat.bg test p-values:
## D I
## 0.56 0.44
## TableGrob (3 x 2) "arrange": 6 grobs
## z cells name grob
## 1 1 (1-1,1-1) arrange gtable[layout]
## 2 2 (1-1,2-2) arrange gtable[layout]
## 3 3 (2-2,1-1) arrange gtable[layout]
## 4 4 (2-2,2-2) arrange gtable[layout]
## 5 5 (3-3,1-1) arrange gtable[layout]
## 6 6 (3-3,2-2) arrange gtable[layout]
ENMTools also allows you to perform linear, blob, and ribbon rangebreak tests as developed in Glor and Warren 2011. The linear and blob tests are two versions of a test that permit one to ask whether the geographic regions occupied by two species are more environmentally different than expected by chance. The ribbon test, meanwhile, is designed to test whether the ranges of two species are divided by a region that is relatively unsuitable to one or both forms.
For the linear and blob tests, you call them very much like you would the identity and background tests. Here’s a linear one using GLM models:
rbl.glm <- rangebreak.linear(ahli, allogus, env, type = "glm", nreps = 4)
##
## Building empirical models...
## Adding environmental data to species ahli
## Processing presence points...
## Processing background points...
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Adding environmental data to species allogus
## Processing presence points...
## Processing background points...
##
## Building replicate models...
##
## Replicate 1 ...
## Adding environmental data to species ahli
## Processing presence points...
## Processing background points...
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Adding environmental data to species allogus
## Processing presence points...
## Processing background points...
##
## Replicate 2 ...
## Adding environmental data to species ahli
## Processing presence points...
## Processing background points...
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Adding environmental data to species allogus
## Processing presence points...
## Processing background points...
##
## Replicate 3 ...
## Adding environmental data to species ahli
## Processing presence points...
## Processing background points...
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Adding environmental data to species allogus
## Processing presence points...
## Processing background points...
##
## Replicate 4 ...
## Adding environmental data to species ahli
## Processing presence points...
## Processing background points...
## Adding environmental data to species allogus
## Processing presence points...
## Processing background points...
rbl.glm
##
##
##
##
## Linear rangebreak test ahli vs. allogus
##
## rangebreak test p-values:
## D I rank.cor env.D env.I env.cor
## 0.8 0.8 0.8 0.4 0.6 0.8
##
##
## Replicates:
##
##
## D I rank.cor env.D env.I env.cor
## ---------- ---------- ---------- ----------- ---------- ---------- -----------
## empirical 0.2227886 0.4647195 -0.5744911 0.0043863 0.0299677 -0.6866762
## rep 1 0.2227886 0.4647195 -0.5744911 0.0044400 0.0295668 -0.7002297
## rep 2 0.0606064 0.2212631 0.7182890 0.6663620 0.8431275 0.8437493
## rep 3 0.2227886 0.4647195 -0.5744911 0.0043322 0.0298150 -0.6912713
## rep 4 0.2732890 0.5762371 -0.8517173 0.0128168 0.0543926 -0.7708189
And here’s a blob test using Bioclim:
rbb.bc <- rangebreak.blob(ahli, allogus, env, type = "bc", nreps = 4)
##
## Building empirical models...
##
## Building replicate models...
##
## Replicate 1 ...
##
## Replicate 2 ...
##
## Replicate 3 ...
##
## Replicate 4 ...
rbb.bc
##
##
##
##
## blob rangebreak test ahli vs. allogus
##
## rangebreak test p-values:
## D I rank.cor env.D env.I env.cor
## 0.8 0.8 0.8 0.4 0.6 0.6
##
##
## Replicates:
##
##
## D I rank.cor env.D env.I env.cor
## ---------- ---------- ---------- ----------- ---------- ---------- ----------
## empirical 0.1328502 0.3177390 0.0706201 0.0206193 0.1146778 0.0927702
## rep 1 0.4358484 0.6454087 0.5254601 0.0746870 0.2579415 0.1767587
## rep 2 0.1328502 0.3177390 0.0706201 0.0198389 0.1068938 0.0782326
## rep 3 0.1328502 0.3177390 0.0706201 0.0227457 0.1120226 0.0846887
## rep 4 0.0120159 0.0728890 -0.1245816 0.0936020 0.1417616 0.1188623
If you want to access the individual replicates (for instance to see how your ranges are being split up), you can find them in the list named “replicate.models” inside your rangebreak test object.
rbl.glm$replicate.models$ahli.rep.1
##
##
## Formula: presence ~ layer.1 + layer.2 + layer.3 + layer.4
## <environment: 0x7fbaee709948>
##
##
## Data table (top ten lines):
##
## Longitude Latitude layer.1 layer.2 layer.3 layer.4 presence
## --- ---------- --------- -------- -------- -------- -------- ---------
## 7 -80.3446 22.0136 2201 1822 978 277 1
## 8 -80.2983 21.9951 2214 1786 986 284 1
## 14 -80.2148 21.9394 2329 1692 1018 269 1
## 9 -80.1776 21.9023 2287 1722 992 266 1
## 13 -80.1776 21.9673 2914 1020 1256 237 1
## 10 -80.1591 21.9673 2984 965 1311 237 1
## 11 -80.1498 21.9858 3042 841 1371 221 1
## 12 -80.1220 21.9301 2898 1033 1231 242 1
## 15 -80.0437 21.9720 2712 1285 1126 250 1
## 1 -80.0106 21.8744 2765 1235 1174 252 1
##
##
## Model:
## Call:
## glm(formula = f, family = "binomial", data = analysis.df[, -c(1,
## 2)])
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -0.5879 -0.1619 -0.0896 -0.0308 3.4353
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -22.053482 9.052203 -2.436 0.0148 *
## layer.1 0.003456 0.002001 1.727 0.0842 .
## layer.2 0.006329 0.002722 2.325 0.0201 *
## layer.3 0.010948 0.005048 2.169 0.0301 *
## layer.4 -0.047868 0.018932 -2.528 0.0115 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 186.63 on 2015 degrees of freedom
## Residual deviance: 163.95 on 2011 degrees of freedom
## AIC: 173.95
##
## Number of Fisher Scoring iterations: 10
##
##
##
## Model fit (training data): class : ModelEvaluation
## n presences : 16
## n absences : 2000
## AUC : 0.7907031
## cor : 0.05489608
## max TPR+TNR at : -4.357708
##
##
## Environment space model fit (training data): class : ModelEvaluation
## n presences : 16
## n absences : 10000
## AUC : 0.9409437
## cor : 0.002497004
## max TPR+TNR at : 0.00263722
##
##
## Proportion of data wittheld for model fitting: 0
##
## Model fit (test data): [1] NA
##
##
## Environment space model fit (test data): [1] NA
##
##
## Suitability:
## class : RasterLayer
## dimensions : 418, 1535, 641630 (nrow, ncol, ncell)
## resolution : 0.008333333, 0.008333333 (x, y)
## extent : -86.90809, -74.11642, 19.80837, 23.2917 (xmin, xmax, ymin, ymax)
## coord. ref. : NA
## data source : in memory
## names : layer
## values : 2.220446e-16, 0.229872 (min, max)
##
##
##
## Notes:
rbl.glm$replicate.models$allogus.rep.1
##
##
## Formula: presence ~ layer.1 + layer.2 + layer.3 + layer.4
## <environment: 0x7fbadeac7860>
##
##
## Data table (top ten lines):
##
## Longitude Latitude layer.1 layer.2 layer.3 layer.4 presence
## --- ---------- --------- -------- -------- -------- -------- ---------
## 17 -79.2527 22.2109 2656 1683 1097 325 1
## 18 -78.7774 22.2241 2373 1967 1067 375 1
## 19 -78.6189 22.2373 2317 1980 1065 374 1
## 20 -78.1039 21.1809 2461 1669 846 252 1
## 22 -77.9983 20.9301 2315 1746 907 265 1
## 21 -78.0247 21.1809 2437 1684 877 264 1
## 26 -77.9323 20.7320 2174 1811 918 267 1
## 24 -77.9719 21.5507 2402 1708 992 325 1
## 23 -77.9719 21.7091 2394 1789 966 364 1
## 25 -77.9323 21.6167 2384 1666 1017 324 1
##
##
## Model:
## Call:
## glm(formula = f, family = "binomial", data = analysis.df[, -c(1,
## 2)])
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -0.6746 -0.2226 -0.1344 -0.1128 3.3294
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 5.2965322 2.6324845 2.012 0.044221 *
## layer.1 -0.0025122 0.0006020 -4.173 3.00e-05 ***
## layer.2 -0.0023336 0.0005927 -3.937 8.24e-05 ***
## layer.3 -0.0014513 0.0009448 -1.536 0.124517
## layer.4 0.0041749 0.0011552 3.614 0.000302 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 629.56 on 3064 degrees of freedom
## Residual deviance: 564.28 on 3060 degrees of freedom
## AIC: 574.28
##
## Number of Fisher Scoring iterations: 7
##
##
##
## Model fit (training data): class : ModelEvaluation
## n presences : 65
## n absences : 3000
## AUC : 0.7685385
## cor : 0.1564749
## max TPR+TNR at : -4.034242
##
##
## Environment space model fit (training data): class : ModelEvaluation
## n presences : 65
## n absences : 10000
## AUC : 0.3509569
## cor : -0.0468568
## max TPR+TNR at : 0.00523012
##
##
## Proportion of data wittheld for model fitting: 0
##
## Model fit (test data): [1] NA
##
##
## Environment space model fit (test data): [1] NA
##
##
## Suitability:
## class : RasterLayer
## dimensions : 418, 1535, 641630 (nrow, ncol, ncell)
## resolution : 0.008333333, 0.008333333 (x, y)
## extent : -86.90809, -74.11642, 19.80837, 23.2917 (xmin, xmax, ymin, ymax)
## coord. ref. : NA
## data source : in memory
## names : layer
## values : 0.002008956, 0.3159311 (min, max)
##
##
##
## Notes:
For the ribbon rangebreak test, you will need one extra thing; a third enmtools.species object representing the occurrence points (for one or both species) that fall within the ribbon of putatively unsuitable habitat. In the case of these two anoles we don’t have such a ribbon, so we’ll just simulate one based on some random points.
ribbon <- enmtools.species(species.name = "ribbon")
ribbon$presence.points <- data.frame(Longitude = runif(n = 10, min = -79, max = -78.5),
Latitude = runif(n = 10, min = 21.7, max = 22.1))
plot(env[[1]])
points(ribbon$presence.points, pch = 16)
ribbon$range <- background.raster.buffer(ribbon$presence.points, 20000, mask = env)
ribbon
##
##
## Range raster:
## class : RasterLayer
## dimensions : 418, 1535, 641630 (nrow, ncol, ncell)
## resolution : 0.008333333, 0.008333333 (x, y)
## extent : -86.90809, -74.11642, 19.80837, 23.2917 (xmin, xmax, ymin, ymax)
## coord. ref. : NA
## data source : in memory
## names : layer.1
## values : 1, 1 (min, max)
##
##
##
## Presence points (first ten only):
##
## Longitude Latitude
## ---------- ---------
## -78.79104 22.09410
## -78.68297 22.08112
## -78.86476 22.06240
## -78.94146 21.94424
## -78.90705 21.98360
## -78.94878 21.95176
## -78.62775 22.06473
## -78.93695 22.09916
## -78.69966 21.79542
## -78.88431 21.86488
##
##
## Background points not defined.
##
## Species name: ribbon
Now we’ll run a ribbon rangebreak test using GLM models with quadratic effects. We also need to tell it the width of the ribbons to generate for the replicates. The units for the width argument are the same units that the presence points are in; e.g., if the points are in decimal degrees you should supply the width of the barrier in decimal degrees.
rbr.glm <- rangebreak.ribbon(ahli, allogus, ribbon, env, type = "glm", f = pres ~ poly(layer.1, 2) + poly(layer.2, 2) + poly(layer.3, 2) + poly(layer.4, 2), width = 0.5, nreps = 4)
##
##
## No background points provided, drawing background from range raster.
## Warning in couldBeLonLat(mask): CRS is NA. Assuming it is longitude/
## latitude
##
## Building empirical models...
## Adding environmental data to species ahli
## Processing presence points...
## Processing background points...
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Adding environmental data to species allogus
## Processing presence points...
## Processing background points...
## Adding environmental data to species ribbon
## Processing presence points...
## Processing background points...
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Adding environmental data to species outside
## Processing presence points...
## Processing background points...
##
## Building replicate models...
##
## Replicate 1 ...
## Adding environmental data to species ahli
## Processing presence points...
## Processing background points...
## Adding environmental data to species allogus
## Processing presence points...
## Processing background points...
## Adding environmental data to species ribbon
## Processing presence points...
## Processing background points...
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Adding environmental data to species outside
## Processing presence points...
## Processing background points...
##
## Replicate 2 ...
## Adding environmental data to species ahli
## Processing presence points...
## Processing background points...
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Adding environmental data to species allogus
## Processing presence points...
## Processing background points...
## Adding environmental data to species ribbon
## Processing presence points...
## Processing background points...
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Adding environmental data to species outside
## Processing presence points...
## Processing background points...
##
## Replicate 3 ...
## Adding environmental data to species ahli
## Processing presence points...
## Processing background points...
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Adding environmental data to species allogus
## Processing presence points...
## Processing background points...
## Adding environmental data to species ribbon
## Processing presence points...
## Processing background points...
## Adding environmental data to species outside
## Processing presence points...
## Processing background points...
##
## Replicate 4 ...
## Adding environmental data to species ahli
## Processing presence points...
## Processing background points...
## Adding environmental data to species allogus
## Processing presence points...
## Processing background points...
## Adding environmental data to species ribbon
## Processing presence points...
## Processing background points...
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Adding environmental data to species outside
## Processing presence points...
## Processing background points...
rbr.glm
##
##
##
##
## ribbon rangebreak test ahli vs. allogus
##
## rangebreak test p-values...
##
## Species 1 vs. Species 2:
## D I rank.cor env.D env.I env.cor
## 0.4 0.4 0.8 0.2 0.2 0.6
##
## Species 1 vs. Ribbon:
## D I rank.cor env.D env.I env.cor
## 0.6 0.4 0.4 0.4 0.2 0.6
##
## Species 2 vs. Ribbon:
## D I rank.cor env.D env.I env.cor
## 0.4 0.4 0.2 0.2 0.2 0.6
##
## Outside vs. Ribbon:
## D I rank.cor env.D env.I env.cor
## 0.4 0.4 0.2 0.2 0.2 1.0
##
##
## Replicates:
##
## Species 1 vs. Species 2:
## D I rank.cor env.D env.I
## empirical 0.2451877 0.4736288 0.10010825 0.007444083 0.04379279
## rep 1 0.3795181 0.6476709 -0.15564493 0.030948699 0.10641443
## rep 2 0.2554989 0.4850860 0.04251252 0.008728950 0.05794699
## rep 3 0.1314541 0.3589306 -0.55056521 0.071408216 0.22532407
## rep 4 0.2949869 0.5535791 0.79866344 0.322984092 0.49930555
## env.cor
## empirical -0.45756055
## rep 1 -0.67681212
## rep 2 -0.53246140
## rep 3 0.09163998
## rep 4 0.23800525
##
## Species 1 vs. Ribbon:
## D I rank.cor env.D env.I
## empirical 0.04528426 0.1339762 0.02299711 0.0007650046 0.006062489
## rep 1 0.04330834 0.1638700 0.53859346 0.3874915095 0.561164149
## rep 2 0.23112863 0.4822056 0.30942044 0.0166055966 0.060663147
## rep 3 0.14892562 0.3676485 -0.44930842 0.0004337121 0.007539412
## rep 4 0.02879743 0.1071481 0.11677177 0.0011657651 0.007994635
## env.cor
## empirical 0.16929615
## rep 1 0.44287600
## rep 2 0.68296572
## rep 3 -0.37121139
## rep 4 -0.08690031
##
## Species 2 vs. Ribbon:
## D I rank.cor env.D env.I
## empirical 0.06176181 0.1982071 -0.72790676 0.0001436678 0.004119129
## rep 1 0.05902818 0.1687426 0.19737183 0.0052153409 0.050853848
## rep 2 0.34627918 0.5995919 0.03751119 0.0046246926 0.027818885
## rep 3 0.45169787 0.7619653 0.81369000 0.2899971046 0.512958289
## rep 4 0.17879371 0.3953037 0.13227575 0.0002320041 0.006036249
## env.cor
## empirical -0.1383704
## rep 1 -0.3791465
## rep 2 -0.7944459
## rep 3 0.2094892
## rep 4 -0.1323387
##
## Outside vs. Ribbon:
## D I rank.cor env.D env.I
## empirical 0.07875459 0.2318005 -0.74196496 0.0002084101 0.005285812
## rep 1 0.05477222 0.1633900 0.14210687 0.0060018527 0.057707449
## rep 2 0.36164902 0.6280478 -0.03373173 0.0068949231 0.032938797
## rep 3 0.48658912 0.7729994 0.88407856 0.0568090043 0.184044794
## rep 4 0.16010628 0.3703136 -0.07916134 0.0009388967 0.012613879
## env.cor
## empirical -0.1543711
## rep 1 -0.4320353
## rep 2 -0.8032067
## rep 3 -0.5891352
## rep 4 -0.2172618
Note that the output table here has slope, intercept, and intercept offset.
rbr.glm$lines.df
## slope intercept offset
## 1 16.2110163 1276.693638 4.0604576
## 2 -0.6171267 -26.744061 0.2937734
## 3 -0.1792872 7.215815 0.2539862
## 4 0.2265418 38.487802 0.2563349
The intercept denotes the intercept corresponding to the CENTER of each ribbon. To get the lines denoting the edges of the ribbons (for example if you want to plot the ribbons on a map), you add and substract the offset. In other words, the top edge of the ribbon is given by y = (slope * x) + intercept + offset, while the bottom edge is given by y = (slope * x) + intercept - offset.
Some of the tests in ENMTools, including some really neat ones that are still in development, require you to build an enmtools.clade object. These objects are simply lists that contain a phylogeny and a set of enmtools.species objects. It’s important that the names of the species objects and their species.name attributes match the names in the phylogeny’s tip.labels. For demonstration, we’re going to build an object for a clade of five anoles from Hispaniola. We have the tree, so we’re just going to grab occurrence data from GBIF using the rgbif package.
library(rgbif)
hisp.anoles <- read.nexus(file = "test/testdata/StarBEAST_MCC.species.txt")
keepers <- c("brevirostris", "marron", "caudalis", "websteri", "distichus")
hisp.anoles <- drop.tip(phy = hisp.anoles, tip = hisp.anoles$tip.label[!hisp.anoles$tip.label %in% keepers])
plot(hisp.anoles)
So there’s our tree. Now we’re going to grab some environmental data.
hisp.env <- stack(list.files("test/testdata/Hispaniola_Worldclim", full.names = TRUE))
hisp.env <- setMinMax(hisp.env)
And then we’ll create a function to build species from GBIF.
# Automate the process of downloading data and removing duds and dupes
species.from.gbif <- function(genus, species, name = NA, env){
# Name it after the species epithet unless told otherwise
if(is.na(name)){
name <- species
}
# Get GBIF data
this.sp <- enmtools.species(presence.points = gbif(genus = genus, species = species)[,c("lon", "lat")],
species.name = name)
# Rename columns, get rid of duds
colnames(this.sp$presence.points) <- c("Longitude", "Latitude")
this.sp$presence.points <- this.sp$presence.points[complete.cases(extract(env, this.sp$presence.points)),]
this.sp$presence.points <- this.sp$presence.points[!duplicated(this.sp$presence.points),]
this.sp$range <- background.raster.buffer(this.sp$presence.points, 50000, mask = hisp.env)
return(this.sp)
}
Now we’ll create five species and add them to a species.clade object that is called brev.clade.
brevirostris <- species.from.gbif(genus = "Anolis", species = "brevirostris", env = hisp.env)
marron <- species.from.gbif(genus = "Anolis", species = "marron", env = hisp.env)
caudalis <- species.from.gbif(genus = "Anolis", species = "caudalis", env = hisp.env)
websteri <- species.from.gbif(genus = "Anolis", species = "websteri", env = hisp.env)
distichus <- species.from.gbif(genus = "Anolis", species = "distichus", env = hisp.env)
brev.clade <- enmtools.clade(species = list(brevirostris, marron, caudalis, websteri, distichus), tree = hisp.anoles)
check.clade(brev.clade)
##
##
## An enmtools.clade object with 5 species
##
## Species names:
## brevirostris caudalis distichus marron websteri
##
## Tree:
##
## Phylogenetic tree with 5 tips and 4 internal nodes.
##
## Tip labels:
## [1] "brevirostris" "caudalis" "distichus" "marron"
## [5] "websteri"
##
## Rooted; includes branch lengths.
##
##
## Data Summary:
## species.names in.tree presence background range
## brevirostris "brevirostris" TRUE 175 0 "present"
## caudalis "caudalis" TRUE 16 0 "present"
## distichus "distichus" TRUE 628 0 "present"
## marron "marron" TRUE 11 0 "present"
## websteri "websteri" TRUE 17 0 "present"
The AOC tests allow you to examine patterns of range, point, and ENM overlap in the context of a phylogeny. This is effectively a generalized version of several analyses: age-range correlation (e.g., Fitzpatrick and Turelli 2006), ENM overlap in the context of a phylogeny (e.g., Knouft et al. 2006, Warren et al. 2008), and point overlaps (e.g., Cardillo and Warren 2016).
These tests require the creation of an enmtools.clade object, as above. AOC tests consist of two steps: first, the average overlap at each node in the phylogeny is calcualted using a method that takes tree topology into account (see Fitzpatrick and Turelli 2006), then we perform a linear regression to measure the relationship between node age and average overlap. Due to the fact that these overlaps violate many of the assumptions of a regular linear regression, however (e.g., errors are not iid), we can’t calculate significance in the typical way. Instead we performa Monte Carlo test, permuting the identity of the tips of the tree and repeating the node averaging and modeling steps. Finally we measure statistical significance by comparing the empirical slope and intercept to the distribution of slopes and intercepts from the Monte Carlo replicates.
First, let’s do one using geog.range.overlaps, as in Fitzpatrick and Turelli 2006. Note that this analysis requires that each of your species have a range raster stored in their species object (we did that as part of the function used above).
range.aoc <- enmtools.aoc(clade = brev.clade, nreps = 50, overlap.source = "range")
summary(range.aoc)
##
##
## Age-Overlap Correlation test
##
## 50 replicates
##
## p values:
## (Intercept) age
## 0.07843137 0.03921569
Now we can do one using point overlaps just by changing the overlap.source argument:
point.aoc <- enmtools.aoc(clade = brev.clade, nreps = 50, overlap.source = "points")
summary(point.aoc)
##
##
## Age-Overlap Correlation test
##
## 50 replicates
##
## p values:
## (Intercept) age
## 0.1568627 0.1176471
Or we can use similarity between ENMs built for each species. Here we’ll use Bioclim models:
bc.aoc <- enmtools.aoc(clade = brev.clade, env = hisp.env, nreps = 50, overlap.source = "bc")
##
##
## No background points provided, drawing background from range raster.
## Warning in couldBeLonLat(mask): CRS is NA. Assuming it is longitude/
## latitude
##
##
## No background points provided, drawing background from range raster.
## Warning in couldBeLonLat(mask): CRS is NA. Assuming it is longitude/
## latitude
##
##
## No background points provided, drawing background from range raster.
## Warning in couldBeLonLat(mask): CRS is NA. Assuming it is longitude/
## latitude
##
##
## No background points provided, drawing background from range raster.
## Warning in couldBeLonLat(mask): CRS is NA. Assuming it is longitude/
## latitude
##
##
## No background points provided, drawing background from range raster.
## Warning in couldBeLonLat(mask): CRS is NA. Assuming it is longitude/
## latitude
summary(bc.aoc)
##
##
## Age-Overlap Correlation test
##
## 50 replicates
##
## p values:
## (Intercept) age
## 0.8235294 0.5882353
Broennimann, O., Fitzpatrick, M. C., Pearman, P. B., Petitpierre, B., Pellissier, L., Yoccoz, N. G., Thuiller, W., Fortin, M.-J., Randin, C., Zimmermann, N. E., Graham, C. H. and Guisan, A. (2012), Measuring ecological niche overlap from occurrence and spatial environmental data. Global Ecology and Biogeography, 21: 481–497. doi:10.1111/j.1466-8238.2011.00698.x
Fitzpatrick, B. M., & Turelli, M. (2006). The geography of mammalian speciation: mixed signals from phylogenies and range maps. Evolution, 60(3), 601-615.
Knouft, J. H., Losos, J. B., Glor, R. E., & Kolbe, J. J. (2006). Phylogenetic analysis of the evolution of the niche in lizards of the Anolis sagrei group. Ecology, 87(sp7).
Levins, R. 1968. Evolution In Changing Environments. Monographs in Population Biology, volume 2. Princeton University Press, Princeton, New Jersey, USA.
Schoener, T. W. 1968. Anolis lizards of Bimini: resource partitioning in a complex fauna. Ecology 49:704- 726.
Warren, D.L., R.E. Glor, and M. Turelli. 2008. Environmental niche identity versus conservatism: quantitative approaches to niche evolution. Evolution 62:2868-2883. doi: 10.1111/j.1558-5646.2008.00482.x
Warren, D.L., M. Cardillo, D.F. Rosauer, and D.I. Bolnick. 2014. Mistaking geography for biology: inferring processes from species distributions. Trends in Ecology and Evolution 29 (10), 572-580. doi: 10.1016/j.tree.2014.08.003